<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Douban_api {
    private $_id;
    private $_isbn;
    private $_title;
    private $_url;
    private static $_instance;
    private static $_api_url  = "http://api.douban.com/v2/book";
    private static $_api_key = "000f935a369e3787002eba0ea3daa695";

    function __construct() {

    }

    
    public static function getInstance() {
        if(!self::$_instance){
            self::$_instance = new Douban_api();
        }
        return self::$_instance;
    }

    public function getSearhResults($query,$start,$count) {
        $this->_url = self::$_api_url . "/search?q=" . $query . "&start=".$start."&count=".$count."&apikey=" . self::$_api_key;
        $results = file_get_contents($this->_url);
        $data = json_decode($results);
        return $data;
    }


    public function getBooksById($book_id) {
        $this->_url = self::$_api_url . "/" . $book_id;
        
        $results = file_get_contents($this->_url);
        $data = json_decode($results);
        return $data;
    }
}
?>